﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dukou.Search
{
    /// <summary>
    /// 搜索器工厂
    /// </summary>
    public class SearcherFactory : ISearcherFactory
    {
        /// <summary>
        /// 获取 / 设置 搜索器集合
        /// </summary>
        public IDictionary<string, ISearcher> Searchers { get; set; }

        #region ISearcherFactory 成员

        /// <summary>
        /// 创建能够查询指定类型内容的搜索器
        /// </summary>
        /// <param name="contentType"></param>
        /// <returns></returns>
        public ISearcher CreateSearcher(string contentType)
        {
            string key = this.Searchers.Keys.SingleOrDefault(k => string.Equals(k, contentType, StringComparison.OrdinalIgnoreCase));
            if (key != null)
            {
                return this.Searchers[key];
            }
            return null;
        }

        #endregion
    }
}
